import routermap from "./routermap";

export function login(params) {
  const base64str = btoa(`webApp:webApp`);
  return http({
    method: "POST",
    headers: {
      Authorization: `Basic ${base64str}`,
    },
    url: "/api-uaa/oauth/token",
    params,
  });
  // return http({
  //   method: "get",
  //   url: "/user/login",
  //   data,
  //   prefix: "MOCK_URL",
  // });
}

export const getUserPermission = (params) => {
  // return http({
  //   method: "GET",
  //   url: `/user/permission`,
  //   params,
  //   prefix: "MOCK_URL",
  // });
  return new Promise((resolve, reject) => {
    resolve({
      code: 200,
      data: routermap(),
      msg: "success",
    });
  });
};

export const authUserPermission = (data) => {
  return http({
    method: "post",
    url: `/api-user/menus/granted`,
    data
  });
};



export function logout() {
  return new Promise((resolve, reject) => {
    resolve({
      code: 200,
      data: null,
      msg: "success",
    });
  });
}

export const getUserInfo = () => {
  return http({
    method: "GET",
    url: `/api-user/users/current`,
  });

  // return http({
  //   method: "GET",
  //   url: `/users/info`,
  //   prefix: "MOCK_URL",
  // });
};

export const getRoleList = () => {
  return http({
    method: "GET",
    url: `/role/list`,
  });
};

export const getUserList = (params) => {
  return http({
    method: "GET",
    url: `/api-user/users`,
    params,
  });
};

export const getUserOrganization = (params) => {
  return http({
    method: "GET",
    url: `/user/organization`,
    params,
  });
};

export const addUser = (data) => {
  return http({
    method: "post",
    url: `/api-user/users/saveOrUpdate`,
    data,
  });
};

export const editUser = (data) => {
  return http({
    method: "post",
    url: `/api-user/users/saveOrUpdate`,
    data,
  });
};

export const deleteUser = (data) => {
  return http({
    method: "delete",
    url: `/api-user/users/${data.id}`,
  });
};

export const resetUserPassword = (data) => {
  return http({
    method: "put",
    url: `/api-user/users/${data.id}/password `,
  });
};

export const updateUserPassword = (data) => {
  return http({
    method: "put",
    url: `/user/password`,
    data,
  });
};

export const updateUserEnabled = (params) => {
  const fd = new FormData();
  Object.keys(params).forEach((key) => {
    fd.append(`${key}`, params[key]);
  });
  return http({
    method: "POST",
    url: `/api-user/users/updateEnabled `,
    data: fd,
  });
};
